package com.mj.app.health.util;

import android.content.Context;
import android.view.Gravity;
import android.widget.Toast;

import com.mj.app.common_util.BaseApplication;


/**
 * ========================================
 * Created by 郝赫 on 2017/10/5.
 * ========================================
 */


public class ToastUtil {

    private static Toast mToast;
    private static int yOffset; // 弹出toast默认的 距底部的距离

    public static void init(Context context){
        if (context == null){
            throw new IllegalArgumentException("Context should not be null");
        }
        if(mToast == null){
            mToast = Toast.makeText(context, null, Toast.LENGTH_SHORT);
            yOffset = mToast.getYOffset();
        }
    }

    public static void show(int resId){
        show(BaseApplication.getContext().getResources().getString(resId));
    }

    public static void show(String content){
        show(content, Gravity.BOTTOM);
    }

    public static void show(String content, int gravity){
        show(content,gravity,Toast.LENGTH_SHORT);
    }

    public static void show(String content, int gravity, int duration){
        if(mToast == null) init(BaseApplication.getContext());
        mToast.setText(content);
        mToast.setDuration(duration);
        mToast.setGravity(gravity,0,yOffset);
        mToast.show();
    }
}
